<style lang="scss">
    @import "../../../utils/base.scss";
</style>
<template>
    <div>
        <!-- 基本信息 -->
        <template id="businessInfo">
            <div class="qheader" :style="{borderBottom: '0px solid rgb(210,210,210)'}">
                <p>业务信息</p>
            </div>
        <div class="gcontent" >
            <Form ref="businessInfo" :rules="networkInfoValidate" :model="networkInfo" :label-width="labelWidth" label-position="left" class="form form_left" >
                <Row >
                    <Col span="8" >
                        <FormItem label="资源池:"  prop="pool">
                            <Input v-if="ifedit"  v-model="networkInfo.pool" :readonly="readonly" />
                            <Select v-else v-model="networkInfo.pool" :transfer='true' style="z-index:999">
                                <Option value="哈尔滨资源池">哈尔滨资源池</Option>
                                <Option value="呼和浩特资源池">呼和浩特资源池</Option>
                                <Option value="业支非池化">业支非池化</Option>
                                <Option value="信息港资源池">信息港资源池</Option>
                            </Select>
                        </FormItem>
                    </Col>
                </Row>
                <Row >
                    <Col span="8" >
                        <FormItem label="接入系统:"  prop="oriSys">
                            <Input v-if="ifedit" v-model="networkInfo.oriSys" :readonly="readonly" />
                            <Select v-else v-model="networkInfo.oriSys" :transfer='true' @on-change="setOriSysInfo" filterable>
                                <Option v-for="(item,index) in allSysList" :value="item.sysName" :key="index">{{item.sysName}}</Option>
                                <Option value="外部系统" >外部系统</Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="8"  class="col_left" >
                        <FormItem label="接入系统联系人:" >
                            <Input  v-model="networkInfo.oriSysContact" :readonly="readonly" />
                        </FormItem>
                    </Col>
                </Row>
                <Row >
                    <Col span="8" >
                        <FormItem label="接入系统联系人电话:"  prop="oriSysPhone">
                            <Input  v-model="networkInfo.oriSysPhone" :readonly="readonly" />
                        </FormItem>
                    </Col>
                    <Col span="8"  class="col_left" >
                        <FormItem label="接入系统联系人邮箱:" prop='oriSysMail'>
                            <Input  v-model="networkInfo.oriSysMail" :readonly="readonly" />
                        </FormItem>
                    </Col>
                </Row>
                <Row >
                    <Col span="8" >
                        <FormItem label="映射类型:"  prop="netMap">
                            <Input v-if="ifedit" v-model="networkInfo.netMap" :readonly="readonly" />
                            <Select v-else v-model="networkInfo.netMap" :transfer='true' style="z-index:999">
                                <Option value="公网">公网</Option>
                                <Option value="承载网-O域">承载网-O域</Option>
                                <Option value="承载网-M域">承载网-M域</Option>
                                <Option value="承载网-B域">承载网-B域</Option>
                                <Option value="承载网-cmit">承载网-cmit</Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="8" class="col_left">
                        <component v-if="networkInfo.netMap==='公网'" ref="file1" :is="'file'" :ifedit="ifedit" :filesList="filesList" v-model="networkInfo.netOpenAppendix"></component>
                    </Col>
                </Row>
                <p style="color:#bbb;margin-bottom: 20px">公网申请请上传近一月dmz主机安全扫描截图，若any网络申请请提交安全管理中心合规平台备案截图。</p>
                <Row >
                    <Col span="22" style="width:96.666667%">
                        <FormItem label="申请描述:"  prop="reqDes">
                            <Input  v-model="networkInfo.reqDes" :readonly="ifedit" maxlength="255" show-word-limit placeholder="请描述申请原因及用途" type="textarea" :autosize="{minRows: 4,maxRows: 6}" />
                        </FormItem>
                    </Col>
                </Row>
            </Form>
        </div>

        </template>

    </div>
</template>
<script>
    import ajax from "../../../ajax_util"
    import Axios from 'axios'
    import { mavonEditor } from 'mavon-editor'
    import 'mavon-editor/dist/css/index.css'
    import inputSearch from '../../../base/input_search'
    import file from './file'

    export default {
        name: "apply",
        components:{
           mavonEditor,inputSearch,file
        },
        data () {
            const validateEntryEndTime = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('请选择期策略失效时间'));
                }else{
                    if(this.networkInfo.actTime === ''){
                        callback(new Error('请选择策略生效时间'));
                    }else if(this.networkInfo.actTime.getTime() > value.getTime()){
                        callback(new Error('策略失效时间不能小于策略生效时间'));
                    }else{
                        callback()
                    }
                }
            };

            return {
                reqId: "",
                mdvalue:"",
                dataInfoEdit: 0,
                showFileMould:false,
                httpHeader:  {
                    Authorization: this.$store.state.token
                },
                disabledDate: {
                    disabledDate (date) {
                        return date && date.valueOf() < Date.now()-24*60*60*1000 || date.valueOf() > 4070880000000;
                    }
                },
                networkInfoValidate:{
                    oriSys:[
                        {required: true,type: 'string', message: '请选择接入系统', trigger: 'change'},
                    ],
                    pool:[
                        {required: true,type: 'string', message: '请输入资源池', trigger: 'change'},
                    ],
                    netMap:[
                        {required: true,type: 'string', message: '请选择策略类型', trigger: 'change'},
                    ],
                    reqDes: [
                        {required: true,type: 'string', message: '请输入申请描述', trigger: 'blur'},
                    ],
                },

                oriuserList:this.PoriuserList,
                taruserList:this.PtaruserList,
                fileUrl:this.CONFIG.file_url,
                readonly: true, //是否只读
                labelWidth: 140,
                bealoonTrue: true,
                file: null,
                loadingStatus: false,
                fileUpLoadAction:"",
                name: "",
                istrue: true,
                networkInfo:this.Papply
            }
        },
        created:function(){
        },
        mounted:function() {
        },

        methods: {
            // 设置目的系统人信息
            setTarSysInfo(value){
                console.log(value)
                if(value == "外部系统"){
                  this.networkInfo.tarSysContactId = 0
                  this.networkInfo.tarSysContact = "无"
                  this.networkInfo.tarSysPhone = "无"
                  this.networkInfo.tarSysMail = "无"
                }else{
                  this.allSysList.some(item =>{
                      if(value == item.sysName){
                          console.log(item)
                          this.networkInfo.tarSysContactId= item.amUser.id
                          this.networkInfo.tarSysContact= item.amUser.user_name
                          this.networkInfo.tarSysPhone = item.amUser.phone
                          this.networkInfo.tarSysMail = item.amUser.email
                          return true
                      }
                  })
                }

            },
            setOriSysInfo(value){
                console.log(value)
                if(value == "外部系统"){
                    this.networkInfo.oriSysId = 0
                    this.networkInfo.oriSysContactId = 0
                    this.networkInfo.oriSysContact = "无"
                    this.networkInfo.oriSysPhone = "无"
                    this.networkInfo.oriSysMail = "无"
                }else{
                  this.allSysList.some(item =>{
                      if(value == item.sysName){
                          console.log(item)
                          this.networkInfo.oriSysId = item.id
                          this.networkInfo.oriSysContactId = item.amUser.id
                          this.networkInfo.oriSysContact = item.amUser.user_name
                          this.networkInfo.oriSysPhone = item.amUser.phone
                          this.networkInfo.oriSysMail = item.amUser.email
                          return true
                      }
                  })
                }
            },
            checkori(list){
                this.oriuserList= list
                list.forEach(item =>{
                    this.networkInfo.oriSysContactId = item.id
                    this.networkInfo.oriSysContact = item.user_name
                    this.networkInfo.oriSysPhone = item.phone
                    this.networkInfo.oriSysMail = item.email
                })
            },
            checktar(list){
                this.taruserList= list
                list.forEach(item =>{
                    this.networkInfo.tarSysContactId= item.id
                    this.networkInfo.tarSysContact= item.user_name
                    this.networkInfo.tarSysPhone = item.phone
                    this.networkInfo.tarSysMail = item.email
                })
            },
            validate(){
                var isSubmit = false
                this.$refs["businessInfo"].validate((valid) => {
                    if (valid) {
                        isSubmit = true
                    } else {
                        this.$refs.base.scrollTop = document.getElementById("businessInfo").offsetTop - 100
                        this.$Message.error('请填写必填项');
                    }
                })
                if (this.networkInfo.netMap==="公网") {
                    if (this.networkInfo.netOpenAppendix == null || this.networkInfo.netOpenAppendix == '' ) {
                        this.$Message.error('请上传附件');
                        isSubmit = false
                    }
                }
                return isSubmit
            },

            //格式化日期
            formatDate(value) {
                var date = new Date(value*1000);
                var year = date.getFullYear();
                var month = this.padDate(date.getMonth() + 1);
                var day = this.padDate(date.getDate());
                return year + '-' + month + '-' + day;
            },
            padDate(value) {
                return value <10 ? '0' + value:value;
            },


        },
        props:{
            filesList:{},
            allSysList:{},
            ifedit: {},
            Papply: {},
            PoriuserList:{
                type: Array,
                default: []
            },
            PtaruserList:{
                type: Array,
                default: []
            },
        },
        watch:{
            Papply(newV,old){
                console.log("newV--------->",newV)
                this.networkInfo = newV
            },
            PoriuserList(newV,old){
                console.log("PoriuserList--------->",newV)
                this.oriuserList = newV
            },
            PtaruserList(newV,old){
                console.log("PtaruserList--------->",newV)
                this.taruserList = newV
            }
        }
    }

</script>
